﻿using com.ytocargo.Application.AcarsInfos;
using com.ytocargo.Application.BackgroundJobs;
using com.ytocargo.Application.ChartsJobs;
using com.ytocargo.Application.FlightCfps;
using com.ytocargo.Application.FlightInfo4Monitors;
using com.ytocargo.Application.Ftp;
using com.ytocargo.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Yto.AutoMapper;
using Yto.AutoMapper.Extensions;
using Yto.Common.Dependency;
using Yto.Modules;
using Yto.Threading;
using Yto.Threading.BackgroundWorkers;

namespace com.ytocargo.Application
{
    [Depends(typeof(ThreadModule), typeof(YtocargoCoreModule), typeof(AutoMapperModule))]
    public class YtocargoApplicationModule : BaseModule
    {

        public override void BeforeInitialize()
        {
            Configuration.MapperConfiguration().ConfigActions.Add(mapperConfig =>
            mapperConfig.AddMaps(typeof(AutoMapperProfile)));
        }

        public override void Initialize()
        {
            CtnManager.RegistAssembly(Assembly.GetExecutingAssembly());
        }

        public override void AfterInitialize()
        {
            var jobWorker = CtnManager.Resolver<IBackgroundManager>();
            jobWorker.Start();

            jobWorker.Add(CtnManager.Resolver<IBackgroundJobManager>());


            var chartJobWorker = CtnManager.Resolver<IChartsJobManager>();
            chartJobWorker.Start();

            var ftpUpdateWorker = CtnManager.Resolver<FTPManager>();
            ftpUpdateWorker.Start();

            var sendFltInfo4MWorker = CtnManager.Resolver<ISendFltInfo4MPeriod>();
            sendFltInfo4MWorker.Start();

            var sendAcarsInfoWorker = CtnManager.Resolver<ISendAcarsInfoPeriod>();
            sendAcarsInfoWorker.Start();

            var sendFlightPlanWorker = CtnManager.Resolver<ISendFlightPlanPeriod>();
            sendFlightPlanWorker.Start();

        }
    }
}
